$(function () {
    $('#contact').click(function () {
        $.ajax({
            type: 'GET',
            url: '/contact/' + $('#userId').text(),
            success: function (result) {
                if (result.statusCode === 200) {
                    // 显示弹框
                    $('#profile').attr('src', result.data.profileUrl);
                    $('#userName').text(result.data.userName);
                    $('#userIntroduction').text('联系方式：' + result.data.userIntroduction);
                    $('#modal-contact').modal('show');
                } else {
                    toastr.error(result.message, {timeOut: 3000});
                }
            }
        });
    });

    $('#login').click(function () {
        window.location.href = '/login';
    });

    /* 分享 */
    $('#share').click(function () {
        navigator.clipboard.writeText(window.location.href).then(function () {
            alert('已复制URL到粘贴板');
        })
    });

    /* 删除 */
    $('#delete').click(function () {
        $.ajax({
            type: 'PUT',
            url: '/post/delete',
            data: {postId: $('#postId').text()},
            success: function (result) {
                if (result.statusCode === 200) {
                    alert('删除成功！');
                    window.location.href = '/profile';
                } else {
                    toastr.error(result.message, {timeOut: 3000});
                }
            }
        });
    });
});